package com.qfedu.inspectionTask.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.common.R;
import com.qfedu.inspectionTask.dto.InspectionDto;
import com.qfedu.inspectionTask.pojo.Inspection;
import com.qfedu.inspectionTask.service.InspectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 功能：
 * 作者：coding
 * 日期：2024/6/14 10:25
 */
@RestController
@RequestMapping("/inspectionTask")
public class InspectionController {
    @Autowired
    private InspectionService inspectionService;

    @GetMapping
    public R<Page<Inspection>> getInspectionTasks(InspectionDto inspectionDto){
        return R.ok(inspectionService.getInspectionTasks(inspectionDto));
    }

    @PostMapping
    public R<Boolean> addDefectTask(@RequestBody Inspection inspection){
//        defectTask.setState(StringUtils.hasLength(defectTask.getDefectUser()) ? 1 : 0);
        return R.ok(inspectionService.save(inspection));
    }

    @PutMapping
    public R<Boolean> updateInspectionTask(@RequestBody Inspection inspection){
//        defectTask.setState(StringUtils.hasLength(defectTask.getDefectUser()) ? 1 : 0);
        return R.ok(inspectionService.updateById(inspection));
    }

    @DeleteMapping("/{id}")
    public R<Boolean> deleteInspectionTask(@PathVariable("id") Long id){
        return R.ok(inspectionService.removeById(id));
    }
}
